#! /usr/bin/env python
# -*- coding: utf-8 -*-


import os
from datetime import datetime


def take_screenshot(page, name):
    screenshots_dir = "screenshots"
    os.makedirs(screenshots_dir, exist_ok=True)

    timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
    screenshot_path = os.path.join(
        screenshots_dir, f"{name}_{timestamp}.png"
    )

    page.screenshot(path=screenshot_path, full_page=True)
    return screenshot_path
